<template>
  <a-card :bordered="false">
    <!-- 卡片区域 -->
    <div style="background-color: #ececec; padding: 10px;" class="my-card">
      <a-row :gutter="16">
        <a-col :span="8">
          <a-card title="今日新增租户数" :bordered="false">
            <p style="font-size:20px">{{countday}}</p>
          </a-card>
        </a-col>
        <a-col :span="8">
          <a-card title="本月新增租户数" :bordered="false">
            <p style="font-size:20px">{{countmonth}}</p>
          </a-card>
        </a-col>
        <a-col :span="8">
          <a-card title="总租户数" :bordered="false">
            <p style="font-size:20px">{{countall}}</p>
          </a-card>
        </a-col>
      </a-row>
    </div>
      <!-- 搜索区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery" style="margin-top:20px">
        <a-row :gutter="24">
          <a-col :md="12" :sm="8">
            <a-form-item label="租户名称" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
              <a-input placeholder="" v-model="queryParam.name"></a-input>
              <!--<a-input placeholder="" v-model="queryParam.roleName"></a-input>-->
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="12" :sm="24">
               <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 21px">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <!-- :pagination="ipagination" -->
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <!-- <a-menu-item>
                <a @click="handleEmpower(record)">授权</a>
              </a-menu-item> -->
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <tenant-modal ref="modalForm" @ok="modalFormOk"></tenant-modal>
  </a-card>
</template>
<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TenantModal from '../system/modules/TenantModal'
  import {getAction} from "../../api/manage";


  export default {
    name: "TenantList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      TenantModal
    },
    data () {
      return {
        description: 'tenant管理页面',
        countday: "",
        cday: true,
        countmonth: "",
        cmonth: true,
        countall: "",
        call: true,
        // 表头
        columns: [
          {
            title:'租户名称',
            align:"center",
            dataIndex: 'name',
          },{
            title:'租户编号',
            align:"center",
            dataIndex: 'id'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
          {
            title:'开始时间',
            align:"center",
            dataIndex: 'beginDate'
          },
          {
            title:'结束时间',
            align:"center",
            dataIndex: 'endDate'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/sys/tenant/list",
          listmap: "/sys/tenant/listred",
          delete: "/sys/tenant/delete",
          deleteBatch: "/sys/tenant/deleteBatch"
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      // handleEmpower(){
      //   this.$message.success('授权');
      // }
    },
    created (){
      getAction(this.url.listmap).then((res) => {
        // console.log("当日新增人数："+res.result.countday);
        // console.log("当月新增人数："+res.result.countmonth);
        // console.log("总租户人数为："+res.result.countall);
        this.countday = res.result.countday;
        this.countmonth = res.result.countmonth;
        this.countall = res.result.countall;
      })
    },
  }
</script>
<style scoped>
.my-card {
  text-align: center;
}
  @import '~@assets/less/common.less';
</style>